/************************* 版权声明 *********************************
 * 
 * 版权所有：Apache License 2.0
 * 
 ************************* 版本声明 *********************************
 *@since jdk1.5
 *@version 0.1
 ************************* 变更记录 *********************************
 *
 * 创建者：bijiqiang Email:bijiqiang@gmail.com   创建日期： 2010-1-6
 * 创建记录：创建类结构。
 * 
 * 修改者：       修改日期：
 * 修改记录：
 *
 * 修改者：       修改日期：
 * 修改记录：
 * ……
 ************************* To  Do *********************************
 *
 * 1、实现所有未实现的方法（抛出UnsupportedOperationException的方法）。
 * 
 ************************* 随   笔 *********************************
 *
 * 
 * 
 ******************************************************************
 */

package com.realgodo.site.web.admin.recruit;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springside.modules.orm.Page;

import com.realgodo.site.entity.site.Recruit;
import com.realgodo.site.service.site.RecruitManager;
import com.realgodo.site.web.admin.AdminDefaultController;

@Scope("prototype")
@Results( { @Result(name = "toindex", type = "redirect", location = "${base}/admin/recruit/") })
public class IndexController extends AdminDefaultController {

	private static final long serialVersionUID = 5093899163897126429L;

	@Autowired
	private RecruitManager recruitManager;

	private Page<Recruit> recruitPage = new Page<Recruit>(PAGE_SIZE);

	private Recruit recruit;

	private Long[] ids;

	public String execute() throws Exception {
		recruitPage.setPageNo(recruitManager.isParamNotNull(getParamMap(),
				Page.PAGE) ? Integer.valueOf((String) recruitManager
				.getParamValue(getParamMap(), Page.PAGE)) : 1);// 查询页数
		this.recruitPage = recruitManager.findEvents(PAGE_SIZE,
				Recruit.OVER_ALL);
		super.setPageInfo(recruitPage);
		return SUCCESS;
	}

	public String remove() throws Exception {
		if (ids.length != 0) {
			this.recruitManager.removeRecruit(ids);
		}
		return "toindex";
	}

	public String add() throws Exception {
		return "add";
	}

	public String save() throws Exception {
		this.recruitManager.createRecruit(recruit);
		return "toindex";
	}

	public String edit() throws Exception {
		if (null != getId()) {
			this.recruit = this.recruitManager.get(getId());
			return "add";
		} else {
			return "toindex";
		}
	}

	public String top() throws Exception {
		if (null != getId()) {
			this.recruitManager.topRecruit(getId());
		}
		return "toindex";
	}

	public String over() throws Exception {
		if (null != getId()) {
			this.recruitManager.overRecruit(getId());
		}
		return "toindex";
	}

	public Page<Recruit> getRecruitPage() {
		return recruitPage;
	}

	public void setRecruitPage(Page<Recruit> recruitPage) {
		this.recruitPage = recruitPage;
	}

	public Recruit getRecruit() {
		return recruit;
	}

	public void setRecruit(Recruit recruit) {
		this.recruit = recruit;
	}

	public Long[] getIds() {
		return ids;
	}

	public void setIds(Long[] ids) {
		this.ids = ids;
	}

}
